package com.spring.beanLife.beanInitAndDestroy;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class LifeCycleBeanPostProcessor implements BeanPostProcessor {

	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (bean instanceof Toyota) {
			System.err.println("postProcessBeforeInitialization....拦截指定bean");
		}
		System.out.println("这句话证明所有容器中的bean都会被 postProcessBeforeInitialization 拦截.. beanName=" + beanName + "==>" + bean);
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if (bean instanceof Toyota) {
			System.err.println("postProcessAfterInitialization.....拦截指定bean");
		}
		System.out.println("这句话证明所有容器中的bean都会被 postProcessAfterInitialization 拦截.. beanName=" + beanName + "==>" + bean);
		return bean;
	}
}
